package at.fhhagenberg.hydrac;

import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;

/**
 * ConsoleOutputHandler
 * 
 * @author Richard Reiffinger
 */
public class ConsoleOutputHandler extends Handler {

  @Override
  public void close() throws SecurityException {
    // Console Ouput-Streams shouldn't be closed.
  }

  @Override
  public void flush() {
    System.out.flush();
    System.err.flush();
  }

  @Override
  public void publish(LogRecord arg0) {
    if (arg0.getLevel() == Level.SEVERE || arg0.getLevel() == Level.WARNING) {
      System.err.println("HydraC: " + arg0.getMessage());
    } else if (arg0.getLevel() == Level.FINEST) {
      System.out.println(arg0.getSourceClassName() + "." + arg0.getSourceMethodName() + ": " + arg0.getMessage());
    } else {
      System.out.println("HydraC: " + arg0.getMessage());
    } // if
  }
}
